package learn_mybatis.mapper;

import entity.User;
import org.junit.Test;

import java.util.List;

public class QuickStartBasedMapper extends BaseMapperTest {
    /**
     * 测试添加，调用UserMapper的insert方法
     */
    @Test
    public void testInsert() {
        User user1 = new User();
        user1.setName("tianshouzhi");
        user1.setAge(27);
        user1.setUsername("renchenhao");
        User user2 = new User();
        user2.setName("wangxiaoxiao");
        user2.setAge(26);
        user2.setUsername("renchenhao");
        userMapper.insert(user1);
    }
    // 测试查询单条记录，调用UserMapper的selectById方法
    @Test
    public void testSelectOne() {
        User user = userMapper.selectById(1);
        assert user != null;
        System.out.println(user);
    }
    // 测试查询多条记录，并将结果封装到一个List中，调用userMapper的selectAll方法
    @Test
    public void testSelectAll() {
        List<User> userlist = userMapper.selectAll();
        System.out.println(userlist);
    }
    // 测试更新，调用userMapper的updateById方法
    @Test
    public void testUpdate() {
        User user = userMapper.selectById(2);
        assert user != null;
        user.setName("huhuamin");
        user.setAge(26);
        int updateCount = userMapper.updateById(user);
        assert updateCount == 1;
    }
    // 测试删除，调用userMapper的deleteById方法
    @Test
    public void testDelete() {
        int deleteCount = userMapper.deleteById(1);
        assert deleteCount == 1;
    }
    // 测试删除，调用userMapper的deleteAll方法
    @Test
    public void testDeleteAll() {
        int deleteCount = userMapper.deleteAll();
        //assert deleteCount == 1;
    }
}
